package com.ruoyi.shop.good.goods.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.mall.common.domain.DtsGoodsProduct;
import com.ruoyi.shop.good.goods.service.DtsGoodsProductService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mall.common.domain.DtsGoods;
import com.ruoyi.shop.good.goods.service.IDtsGoodsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品列表Controller
 *
 * @author ruoyi
 * @date 2025-02-19
 */
@RestController
@RequestMapping("/good/commodity/goods")
public class DtsGoodsController extends BaseController
{
    @Autowired
    private IDtsGoodsService dtsGoodsService;

    //商品规格Service
    @Autowired
    private DtsGoodsProductService dtsGoodsProductService;


    /**
     * 查询商品列表列表
     */
    @PreAuthorize("@ss.hasPermi('commodity:goods:list')")
    @GetMapping("/list")
    public TableDataInfo list(DtsGoods dtsGoods)
    {
        startPage();
        List<DtsGoods> list = dtsGoodsService.selectDtsGoodsList(dtsGoods);
        return getDataTable(list);
    }


    @PreAuthorize("@ss.hasPermi('commodity:goods:list1')")
    @GetMapping("/list1")
    public TableDataInfo list1(DtsGoods dtsGoods1)
    {
        List<DtsGoods> list = dtsGoodsService.selectDtsGoodsList1(dtsGoods1);
        return getDataTable(list);
    }

    /**
     * 获取商品规格
     */
    @PreAuthorize("@ss.hasPermi('commodity:goods:product')")
    @GetMapping("/product")
    public TableDataInfo product(Long id)
    {
        List<DtsGoodsProduct> list = dtsGoodsService.selectGoodBatchsList(id);
        return getDataTable(list);
    }

    /**
     * 获取商品规格详情列表
     */
    @PreAuthorize("@ss.hasPermi('commodity:goods:productXiangQ')")
    @GetMapping("/productXiangQ")
    public AjaxResult productXiangQ(Long id)
    {
        DtsGoodsProduct dtsGoodsProduct = dtsGoodsProductService.seelctXiangqing(id);
        return success(dtsGoodsProduct);
    }

    /**
     * 导出商品列表列表
     */
    @PreAuthorize("@ss.hasPermi('commodity:goods:export')")
    @Log(title = "商品列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DtsGoods dtsGoods)
    {
        List<DtsGoods> list = dtsGoodsService.selectDtsGoodsList(dtsGoods);
        ExcelUtil<DtsGoods> util = new ExcelUtil<DtsGoods>(DtsGoods.class);
        util.exportExcel(response, list, "商品列表数据");
    }

    /**
     * 获取商品列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('commodity:goods:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dtsGoodsService.selectDtsGoodsById(id));
    }

    /**
     * 新增商品列表
     */
    @PreAuthorize("@ss.hasPermi('commodity:goods:add')")
    @Log(title = "商品列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DtsGoods dtsGoods)
    {
        return toAjax(dtsGoodsService.insertDtsGoods(dtsGoods));

    }

    /**
     * 修改商品列表
     */
    @PreAuthorize("@ss.hasPermi('commodity:goods:edit')")
    @Log(title = "商品列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DtsGoods dtsGoods)
    {
        return toAjax(dtsGoodsService.updateDtsGoods(dtsGoods));
    }

    /**
     * 删除商品列表
     */
    @PreAuthorize("@ss.hasPermi('commodity:goods:remove')")
    @Log(title = "商品列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dtsGoodsService.deleteDtsGoodsByIds(ids));
    }

    @GetMapping("/goods/{id}")
    public AjaxResult selGoods(@PathVariable Long id) {
        return success(dtsGoodsService.selGoods(id));
    }
}

